package com.xtaller.lazy.lib.convert;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @version V1.0
 * @author: Taller
 * @date: 2019-04-03
 * @Description: 数据验证类
 */
public class V {
    public V() {
    }

    public static Boolean isEmpty(Object field) {
        if (field == null) {
            return true;
        } else {
            return field.toString().trim().length() == 0 ? true : false;
        }
    }

    public static Boolean isLength(Object field, int len) {
        return field.toString().trim().length() < len ? true : false;
    }

    public static JSONObject checkEmpty(Map<String, String> kv, Object object) {
        Set<String> keys = kv.keySet();
        JSONObject vObject = J.o2j(object);
        JSONObject result = new JSONObject();
        result.put("check", false);
        Iterator var5 = keys.iterator();

        while(var5.hasNext()) {
            String key = (String)var5.next();
            if (isEmpty(vObject.get(key))) {
                result.put("check", true);
                result.put("message", kv.get(key));
                break;
            }
        }

        return result;
    }

    public static Boolean isEqual(String... val) {
        return StringUtils.equals(val[0], val[1]) ? true : false;
    }

}
